class Cadastro::Instituicao::Bancaria::ContasController < ApplicationController
  # GET /instituicao/bancaria/conta
  # GET /instituicao/bancaria/conta.xml
  def index
    @contas = Conta.find(:all).paginate :page => params[:pagina], :per_page => 15
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @contas }
    end
  end

  # GET /instituicao/bancaria/conta/1
  # GET /instituicao/bancaria/conta/1.xml
  def show
    @conta = Conta.find(params[:id])
    @field_disable = true
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @conta }
    end
  end

  # GET /instituicao/bancaria/conta/new
  # GET /instituicao/bancaria/conta/new.xml
  def new
    @conta = Conta.new
    @agencia_bancaria = AgenciaBancaria.new
    @field_disable = false
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @conta }
    end
  end

  # GET /instituicao/bancaria/conta/1/edit
  def edit
    @conta = Conta.find(params[:id])
    @field_disable = true
  end
  
  # GET /instituicao/bancaria/conta/adicionar_referencia_bancaria
  def adicionar_referencia_bancaria
    @referencia_bancaria = ReferenciaBancaria.new
    render :partial => 'referencia_bancaria_form', :object => [@referencia_bancaria]
  end

  # POST /instituicao/bancaria/conta
  # POST /instituicao/bancaria/conta.xml
  def create
    @conta = Conta.new(params[:conta])
    respond_to do |format|
      if @conta.save
        flash[:notice] = 'Conta criada com sucesso.'
        format.html { redirect_to(@conta) }
        format.xml  { render :xml => @conta, :status => :created, :location => @conta }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @conta.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /instituicao/bancaria/conta/1
  # PUT /instituicao/bancaria/conta/1.xml
  def update
    @conta = Conta.find(params[:id])
    respond_to do |format|
      if @conta.update_attributes(params[:conta])
        flash[:notice] = 'Conta atualizada com sucesso.'
        format.html { redirect_to(@conta) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @conta.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /instituicao/bancaria/conta/1
  # DELETE /instituicao/bancaria/conta/1.xml
  def destroy
    @conta = Conta.find(params[:id])
    respond_to do |format|
      if @conta.destroy
        flash[:success] = 'Conta excluída com sucesso.'
        format.html { redirect_to(conta_path) }
        format.xml  { head :ok }
      end
    end
  end
end